package com.iemes.controller.order;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.inject.Inject;

import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.iemes.controller.base.BaseResponse;
import com.iemes.controller.index.BaseController;
import com.iemes.entity.OrderperFormMap;
import com.iemes.mapper.order.OrderMapper;
import com.iemes.plugin.PageView;
import com.iemes.util.Common;
import com.iemes.util.FormMap;
import com.iemes.util.PublicUtils;

@RequestMapping("/orderReport/")
@Controller
public class OrderReportController extends BaseController {

	@Inject
	private OrderMapper orderMapper;

	/**
	 * 取报表数据方法（公共）
	 * 
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping("getReportData")
	public BaseResponse getReportData() throws Exception {
		BaseResponse response = new BaseResponse();
		FormMap<String, ?> formMap = getFormMap(FormMap.class);
		Map<String, Object> map = new HashMap<String, Object>();
		if (formMap != null && formMap.size() != 0) {
			Set<String> set = formMap.keySet();
			for (String key : set) {
				map.put(key, formMap.get(key));
			}
		}

		List<Map<String, Object>> list = null;
		String reportMethod = formMap.getStr("reportMethod");
		if (reportMethod.equals("getTodayClientOrder")) {
			list = orderMapper.getTodayClientOrder();
		} else if (reportMethod.equals("getOrderfinishTime")) {
			list = orderMapper.getOrderfinishTime();
		}
		response.setResult(true);
		response.setData(list);
		response.setMessage("执行成功");
		return response;
	}


	// 周统计
	@ResponseBody
	@RequestMapping("Week_statistics")
	public String Week_statistics(Model model) {
		return Common.BACKGROUND_PATH + "/order/order_week_statistics";
	}

	// 预排分页，默认7天
	@ResponseBody
	@RequestMapping("orderWeek_findByPage")
	public PageView findByPage(String pageNow, String pageSize)
			throws Exception {
		
		return pageView;
	}

	// 月统计
	@ResponseBody
	@RequestMapping("Month_statistics")
	public String Month_statistics(Model model) {
		return Common.BACKGROUND_PATH + "/order/order_month_statistics";
	}

	// 年统计
	@ResponseBody
	@RequestMapping("Year_statistics")
	public String Year_statistics(Model model) {
		return Common.BACKGROUND_PATH + "/order/order_year_statistics";
	}

}
